var Edit = {
		data: {},
		modelPath: "/signature"
}

Edit.save = function(){
	Edit.collectData();
	var ajax = new $ax(Base.ctxPath + Edit.modelPath+"/save", function(data){
		Tip.success("操作成功!");
		window.parent.Index.table.refresh();
		Edit.close();
	},function(data){
		Tip.error("操作失败!" + data.responseJSON.message + "!");
		setTimeout(function(){
			$("#submitBtn").removeAttr("disabled");
		},200); 
	});
	ajax.set(Edit.data);
	ajax.start();
}
Edit.submit = function(){
	Tip.confirm("确认提交？", function(){
		Edit.collectData();
		var ajax = new $ax(Base.ctxPath + Edit.modelPath+"/submit", function(data){
			Tip.success("操作成功!");
			window.parent.Index.table.refresh();
			Edit.close();
		},function(data){
			Tip.error("操作失败!" + data.responseJSON.message + "!");
			setTimeout(function(){
				$("#submitBtn").removeAttr("disabled");
			},200); 
		});
		ajax.set(Edit.data);
		ajax.start();
	});
}

Edit.close = function () {
	window.parent.layer.close(window.parent.Index.layerIndex);
};

Edit.collectData = function () {
	$(".form-control").each(function(i,v){ 
		Edit.data[v.id] = v.value;
	})
//	var html = $('.summernote').summernote('code').replace(/<p><br><\/p>/g,'');
//	Edit.data['htmlText'] = html;
};

Edit.clearData = function() {
	$(".form-control").each(function(i,v){ 
		$("#"+v.id).val("");
	})
}


$(function(){
	//表单校验
	$("#submitForm").validate({
		rules: {
			channel: "required",
			fundModel: "required",
		}, 
		messages: {
		},
		submitHandler:function(form){
			Edit.submit();
		}
	});

	$("#saveBtn").on("click", function(){
		Edit.save();
	});

	layui.use('upload', function(){
		var $ = layui.jquery,upload = layui.upload;

		//普通图片上传
		var uploadInst = upload.render({
			elem: '#imageFile',
			url : Base.ctxPath + '/fastdfs/uploadFile',
			auto : true,
			size : 10240, //限制文件大小，单位 KB
			//multiple: true
			//bindAction : '#test9',
			accept : 'file', //普通文件
			exts : 'png|gif|jpg', //只允许上传压缩文件
			before: function(obj){
				obj.preview(function(index, file, result){
					 $('#imageDesc').attr('src', result); //图片链接（base64）
				});
			},
			done: function(res){
				if(res){
					if(res.success){
						Tip.confirm("解析成功,确认是否覆盖原内容", function(){
							$("#imageUrl").val(res.content)
//							$("#imagePath").attr("href",res.fastPath)
							//		return "<a href='"+row.fastUrl+"' target='_blank'>"+value+"</a>";
						});
					}else{
						Tip.error("操作失败!" + res.message + "!");
					}
				}else{
					Tip.error("操作失败!");
				}
			}
		});
	
		upload.render({
			elem : '#keystoreFile',
			url : Base.ctxPath + '/fastdfs/uploadFile',
			auto : true,
			size : 10240, //限制文件大小，单位 KB
			//multiple: true
			//bindAction : '#test9',
			accept : 'file', //普通文件
//			exts : 'pdf|doc|docx', //只允许上传压缩文件
			done : function(res) {
				if(res){
					if(res.success){
						Tip.confirm("解析成功,确认是否覆盖原内容", function(){
							$("#keystoreUrl").val(res.content)
							$("#keystorePath").attr("href",res.fastPath)
							//		return "<a href='"+row.fastUrl+"' target='_blank'>"+value+"</a>";
						});
					}else{
						Tip.error("操作失败!" + res.message + "!");
					}
				}else{
					Tip.error("操作失败!");
				}
			}
		});
	});

});
